<?php
namespace Admin\Controller;

use Think\Controller;

class ServicesController extends BaseController{
    public function index(){
        $m = M("services");
        $data=$m->select();
        $this->assign("data",$data);
        $this->display();
    }
    public function doadd(){
        $data=I("post.");
        $m = M("services");
        //判断服务器名称不可为空； 
        if(empty($data['name'])){
            $this->error("服务名不可为空");
        }

        //判断内容不可为空； 
        if(empty($data['contact'])){
            $this->error("内容不可为空");
        } 
        //添加信息
        if($data=$m->create()){
            //单图片上传
             if(!empty($_FILES['thumb'])){
                    $info=$this->uploads();
                    $thumb=$info['savepath'].$info['savename'];
                    $data['thumb']=$thumb;
             }
             //多图片上传
             if(!empty($_FILES['images'])){
                 $info =$this->uploades();
                    $thumb=$info['savepath'].$info['savename'];
                    $data['thumb']=$thumb;
             }
             //添加插入时间
            $data['inserttime']=time();
            //执行添加
            if($m->add($data)){
                    $this->success("添加成功",U("index"));
                }else{
                    $this->error("添加失败");
                }
            }else{
                $this->error("匹配失败");
            }

    }
    //修改服务信息
    public function edit(){
        $id =I("get.id");
        $where ="id = ".$id;
        $m = M("services");
        $data=$m->where($where)->find();
        $this->assign("data",$data);
        $this->display();
    }
    //删除服务信息； 
    public function delete(){
        $id = I("get.id");
        $where = "id = ".$id;
        $m = M("services");
        $tag=$m->where($where)->delete();
        if($tag !== false){
            $this->success("删除成功",U("index"));
        }else{
            $this->error("删除失败");
        }
        
    }
    
    
    
 

   
}